<template>
	<view class="content">
		<mescroll-uni ref="mescrollRef" @init="mescrollInit" @up="upCallback" :up="upOption" :down="{ use: false }">
			<view class="section-0">
				<view class="section-body">
					<view class="tab">
						<view @click="setCurIdx(idx, item.name)"
							:class="`item ${curName === item.name ? 'item__active' : ''} ${curIdx + 1 === idx ? 'item__active_next' : ''}`"
							v-for="(item, idx) in tabList" :key="item.id">
							<view class="label">
								{{item.name}}{{`(${item.quantity})`}}
							</view>
							<view class="shape">
								<view class="shape-body"></view>
							</view>
							<view class="shape shape-mirrow">
								<view class="shape-body"></view>
							</view>
						</view>
					</view>
					<view class="form">
						<view class="form-item">
							<view class="label">搜索</view>
							<view class="shape"></view>
							<view class="input">
								<u--input placeholderClass="input-placeholder" class="input-body" placeholder="作业票名称"
									v-model="form.ticket_name"></u--input>
							</view>
						</view>
						<view class="actions">
							<view class="action" @click="handleResetForm()">
								<text>重</text>
								<text>置</text>
							</view>
							<view class="action search" @click="handleSearch()">
								<text>查</text>
								<text>询</text>
							</view>
						</view>
					</view>
					<view class="list">
						<view :class="`item ${expandList.indexOf(item.id) !== -1 ? 'item__expand' : ''}`"
							v-for="(item, index) in list" :key="item.id + '_' + index">
							<view class="parent">
								<view class="name">
									<!-- <text style="max-width: 480rpx" -->
									<text>{{ index + 1 }}.{{ item.ticket_name }}</text>
								</view>
								<view class="ticketNumber">
									<text> 作业编号：{{ item.ticket_no }} </text>
									<text>施工人数：{{ item.construction_personnel_num }}</text>
								</view>
								<view class="time">
									<text>计划开始时间：{{ item.planned_start_time }}</text>
									<text>计划结束时间：{{ item.planned_end_time }}</text>
								</view>
								<view class="people">
                                <text>实际开始时间：{{ item.actual_start_time }}</text>
								<text>实际结束时间：{{ item.actual_end_time}}</text>
                                </view>
								<view class="person">
									<text>工作负责人：{{ item.work_charge_person }}</text>
									<text>安全监护人：{{ item.safety_guardian_person }}</text>
								</view>
								<view class="other">
									<view class="other1" @click="go(item)">作业票详情</view>
									<!-- <view class="other1" @click="goVideo(item)">站班会</view> -->
									<!-- <viewv-show="item.technical_plan_file_path != null"class="other1"@click="preview(item.technical_plan_file_path)">施工方案</view> -->
								</view>
							</view>
						</view>
						<view class="problem-wrapper" v-if="list.length<=0">
							<image src="https://www.mescroll.com/img/mescroll-empty.png"></image>
							<view class="">~ 空空如也 ~</view>
						</view>
					</view>
				</view>
			</view>
		</mescroll-uni>
	</view>
</template>

<script>
	import {
		ticketChildListNormalApi,
		statisticalTicket
	} from "@/api/statistics.js";
	import {
		mapGetters
	} from "vuex";
	export default {
		data() {
			return {
				form: {
					ticket_name: "",
				},
				project_id: "",
				list: [],
				expandList: [],
				mescroll: null, // mescroll实例对象 (此行可删,mixins已默认)
				upOption: {
					textNoMore: "-- 没有更多了 --",
				},
				curTab: {
					id: 1,
					name: '执行中'
				},
				curName: '执行中',
				curIdx: 0,
				tabList: [{
						name: '执行中',
						id: 1,
						quantity: 0
					},
					{
						name: '已完成',
						id: 2,
						quantity: 0
					},
					{
						name: '暂停中',
						id: 3,
						quantity: 0
					},
				],
			};
		},
		computed: {
			...mapGetters({
				curProject: "system/getCurProject",
			}),
		},
		methods: {
			setCurIdx(idx, name) {
				this.curIdx = idx;
				this.curName = name;
				this.expandList = [];
				this.mescroll.resetUpScroll();
				this.mescroll.scrollTo(0, 0);
				// this.fetchInfo(idx + 1)
			},
			handleResetForm() {
				for (let key in this.form) {
					this.form[key] = "";
				}
				this.mescroll.resetUpScroll();
				this.mescroll.scrollTo(0, 0);
			},
			handleSearch() {
				this.mescroll.resetUpScroll();
				this.mescroll.scrollTo(0, 0);
			},
			// goto(path) {
			// 	console.log('1111')
			// 	uni.navigateTo({
			// 		url: path,
			// 	});
			// },
			goVideo(item) {
				uni.navigateTo({
					url: `/pages/statistics/safety/ticket/video/index?project_id=${item.project_id}&ticket_id=${item.ticket_id}`,
				});
			},
			preview(url) {
				uni.navigateTo({
					url: "/pages/pdf/index?url=" + url,
				});
			},
			go(item) {
				let params = {
					project_id: item.project_id,
					project_name: item.project_name,
					id: item.id
				};
				uni.navigateTo({
					url: "/pages/statistics/safety/ticket/details/index?params=" +
						JSON.stringify(params),
				});
			},
			mescrollInit(mescroll) {
				this.mescroll = mescroll;
			},
			/*上拉加载的回调*/
			async upCallback() {
				const {
					data
				} = await ticketChildListNormalApi({
					id: this.curProject.id,
					process_status: this.curName,
					ticket_name: this.form.ticket_name
				});
				this.list = data.data.data;
				const quantity = await statisticalTicket({
					project_id: this.curProject.id,
				});
				//添加每项作业票的数量
				this.tabList.forEach(item => {
					if (item.name === '执行中') {
						item.quantity = quantity.data.data.ticket_executing
					} else if (item.name === '已完成') {
						item.quantity = quantity.data.data.ticket_finsh
					} else {
						item.quantity = quantity.data.data.ticket_stop
					}
				})
				this.mescroll.endErr();
			},
		},
	};
</script>

<style lang="scss" scoped>
	.section-0 {
		z-index: 10;
		background-color: #3a5df5;

		// border-top-left-radius: 50rpx;
		// border-top-right-radius: 50rpx;
		.section-body {
			width: 100%;
			height: 100%;
			border-top-left-radius: 50rpx;
			border-top-right-radius: 50rpx;
			background-color: #fff;
			overflow: hidden;

			.tab {
				width: 100%;
				height: 80rpx;
				@include clear();
				background-color: #1534ce;

				.item {
					width: 33.33%;
					float: left;
					height: 80rpx;
					background-color: #1534ce;
					position: relative;

					.label {
						height: 80rpx;
						line-height: 80rpx;
						position: relative;
						z-index: 10;
						box-sizing: border-box;
						text-align: center;
						width: 100%;
						font-size: 26rpx;
						font-weight: normal;
						font-stretch: normal;
						letter-spacing: 0rpx;
						color: #ffffff;
					}

					.shape {
						z-index: 1;
						width: 50rpx;
						height: 50rpx;
						position: absolute;
						bottom: 0;
						left: -50rpx;
						background: #000;
						display: none;
						background-color: #fff;
						overflow: hidden;

						.shape-body {
							width: 50rpx;
							height: 50rpx;
							background-color: #1534ce;
							border-bottom-right-radius: 40rpx;
						}
					}

					.shape-mirrow {
						z-index: 1;
						left: 0;
						display: none;

						.shape-body {
							border-bottom-right-radius: 0rpx;
							border-bottom-left-radius: 40rpx;
						}
					}
				}

				.item__active {
					border-top-left-radius: 40rpx;
					border-top-right-radius: 40rpx;
					background-color: #fff;

					.label {
						color: #46464a;
					}

					.shape {
						display: block;
					}

					.shape-mirrow {
						display: none;
					}
				}

				.item__active_next {
					border-bottom-right-radius: 50rpx;

					.shape {
						display: none;
					}

					.shape-mirrow {
						display: block;
					}
				}
			}
		}

		.list {
			width: 670rpx;
			box-sizing: border-box;
			margin-left: 40rpx;
			border-top: 2rpx solid #d8e4f2;

			.problem-wrapper {
				color: #808080;
				margin: 0 auto;
				text-align: center;

				image {
					margin-top: 300rpx;
					width: 200rpx;
					height: 200rpx;
				}
			}

			.item {
				width: 670rpx;
				padding: 10rpx 0;
				border-bottom: solid 2rpx #f2f2f0;

				.parent {
					width: 672rpx;
					@include clear();

					.name {
						// 将两个view元素分左右对齐
						display: flex;
						justify-content: space-between;
						width: 100%;
						line-height: 30rpx;
						padding: 26rpx 0;
						font-size: 31rpx;
						font-weight: normal;
						font-stretch: normal;
						letter-spacing: 2rpx;
						color: #3b3c40;
						float: left;
						word-break: break-all;
					}

					.ticketNumber {
						display: flex;
						justify-content: space-between;
						width: 100%;
						float: left;
						font-size: 19rpx;
						font-weight: normal;
						font-stretch: normal;
						letter-spacing: 0rpx;
						color: #7f98ae;
						margin-bottom: 12rpx;
					}

					.time {
						display: flex;
						justify-content: space-between;
						width: 100%;
						float: left;
						font-size: 19rpx;
						font-weight: normal;
						font-stretch: normal;
						letter-spacing: 0rpx;
						color: #7f98ae;
						margin-bottom: 12rpx;
					}

					.people {
						width: 100%;
						float: left;
						display: inline-flex; //将对象作为内联块级弹性伸缩盒显示 父元素默认根据子元素宽高自适应
						display: flex;
						flex-direction: row;
						justify-content: space-between;
						font-family: AdobeHeitiStd-Regular;
						font-size: 20rpx;
						font-weight: normal;
						font-stretch: normal;
						line-height: 34rpx;
						letter-spacing: 0rpx;
						color: #7f98ae;
					}

					.person {
						width: 100%;
						float: left;
						display: inline-flex; //将对象作为内联块级弹性伸缩盒显示 父元素默认根据子元素宽高自适应
						display: flex;
						flex-direction: row;
						justify-content: space-between;
						font-family: AdobeHeitiStd-Regular;
						font-size: 20rpx;
						font-weight: normal;
						font-stretch: normal;
						line-height: 34rpx;
						letter-spacing: 0rpx;
						color: #7f98ae;
						margin-top: 12rpx;
					}

					.other {
						width: 100%;
						float: left;
						display: inline-flex; //将对象作为内联块级弹性伸缩盒显示 父元素默认根据子元素宽高自适应
						display: flex;
						flex-direction: row;
						justify-content: space-between;

						// flex-wrap: nowrap; //项目不换行排列
						.other1 {
							// align-self: center;
							font-family: AdobeHeitiStd-Regular;
							font-size: 31rpx;
							font-weight: normal;
							font-stretch: normal;
							line-height: 64rpx;
							letter-spacing: 0rpx;
							color: #1534ce;
						}
					}

					.action {
						float: right;
						width: 32rpx;
						margin-right: 48rpx;
						height: 100%;
						line-height: 82rpx;
						text-align: center;
						color: #3b3c40;

						.iconfont {
							font-size: 32rpx;
							transition: 0.2s ease;
							transform: rotate(90deg);
						}
					}
				}
			}

			.item__expand {
				.parent {
					.action {
						.iconfont {
							transform: rotate(-90deg);
						}
					}
				}

				.child {
					box-shadow: 0rpx 10rpx 10rpx 0rpx rgba(0, 0, 0, 0.03) inset;
				}
			}
		}

		.actions {
			width: 100%;
			height: 50rpx;
			margin-top: 29rpx;
			padding-bottom: 40rpx;
			display: flex;
			justify-content: space-between;

			.action {
				width: 288rpx;
				height: 48rpx;
				background-color: #395cf5;
				border-radius: 20rpx;
				text-align: center;
				line-height: 48rpx;
				font-size: 26rpx;
				font-weight: normal;
				font-stretch: normal;
				color: #ffffff;

				text {
					&:first-child {
						margin-right: 20rpx;
					}
				}
			}

			.search {
				background-color: #1534ce;
			}
		}

		.form {
			width: 100%;
			padding: 0 75rpx;
			padding-top: 40rpx;
			box-sizing: border-box;

			.form-time {
				width: 600rpx;
				min-height: 48rpx;
				margin: 0 auto;
				margin-bottom: 9rpx;

				@include clear;

				.label {
					float: left;
					width: 134rpx;
					height: 48rpx;
					text-align: center;
					line-height: 44rpx;
					font-size: 26rpx;
					font-weight: normal;
					font-stretch: normal;
					letter-spacing: 0rpx;
					color: #1534ce;
				}

				.wrapper {
					float: left;
					width: calc(100% - 134rpx);
					line-height: 48rpx;

					.item {
						float: left;
						display: inline-block;
						height: 48rpx;
						border-radius: 35rpx;
						padding: 0 20rpx;
						background-color: #395cf5;
						text-align: center;
						font-size: 26rpx;
						line-height: 48rpx;
						color: #fff;
						margin-left: 10rpx;
						transition: 0.3s ease;
						margin-bottom: 16rpx;
					}

					.item__active {
						background-color: #1534ce;
					}
				}
			}

			.form-item {
				width: 600rpx;
				height: 48rpx;
				border-radius: 20rpx;
				border: solid 2rpx #1534ce;
				margin: 0 auto;
				margin-bottom: 25rpx;

				&:last-child {
					margin-bottom: 34rpx;
				}

				@include clear();

				.label {
					float: left;
					width: 134rpx;
					height: 48rpx;
					text-align: center;
					line-height: 44rpx;
					font-size: 26rpx;
					font-weight: normal;
					font-stretch: normal;
					letter-spacing: 0rpx;
					color: #1534ce;
				}

				.shape {
					width: 3rpx;
					height: 32rpx;
					background-color: #7f98ae;
					float: left;
					margin-top: 8rpx;
				}

				.input {
					float: left;
					width: calc(100% - 134rpx - 3rpx);

					.input-body {
						box-sizing: border-box;
						width: 100%;
						height: 44rpx;
						padding: 0 !important;
						border: none;
						padding-left: 30rpx !important;
						padding-right: 30rpx !important;
						font-size: 26rpx;
						font-weight: normal;
						font-stretch: normal;
						letter-spacing: 0rpx;
						color: rgba(0, 0, 0, 0.7);
					}

					.input-placeholder {
						font-size: 26rpx;
						font-weight: normal;
						font-stretch: normal;
						letter-spacing: 0rpx;
						color: rgba(0, 0, 0, 0.5);
					}
				}
			}
		}
	}
</style>
